package com.itheima.demo;

import com.alibaba.druid.pool.DruidDataSource;
import com.alibaba.druid.pool.DruidPooledConnection;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import java.sql.SQLException;

public class demo1 {
    //数据库连接池测试
    @Test
    public void test01() throws SQLException {
        DruidDataSource ds = new DruidDataSource();
        //配置数据库四大基本特征
        ds.setDriverClassName("com.mysql.jdbc.Driver");
        ds.setUrl("jdbc:mysql://192.168.23.129:3306/db19");
        ds.setUsername("root");
        ds.setPassword("wuyanzu7095.");
        DruidPooledConnection connection = ds.getConnection();
        System.out.println(connection);
    }

    //ioc容器配置数据库连接池
    @Test
    public void  test02() throws SQLException {
        ApplicationContext ac = new ClassPathXmlApplicationContext("spring.xml");
        //从ioc容器获取对象
        DruidDataSource bean = ac.getBean(DruidDataSource.class);
        DruidPooledConnection connection = bean.getConnection();
        System.out.println(connection);
    }
}
